DROP TRIGGER TEST_TRI;
DROP SEQUENCE TEST_VAR1_SEQ;
DROP TABLE TEST;

--创建表
CREATE TABLE TEST(
VAR1 INT PRIMARY KEY,
VAR2 VARCHAR2(10) NOT NULL UNIQUE
);

--创建序列
CREATE SEQUENCE TEST_VAR1_SEQ
INCREMENT BY 1
START WITH 1
MAXVALUE 4096
CYCLE
NOCACHE;

--创建触发器
CREATE TRIGGER TEST_TRI BEFORE
INSERT ON TEST FOR EACH ROW WHEN(NEW.VAR1 IS NULL)
BEGIN
SELECT TEST_VAR1_SEQ.NEXTVAL INTO:NEW.VAR1 FROM DUAL;
END;
